package ch10;

import java.util.Scanner;

public class Zxf6 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int k = 2;//数组长度；
        String[] names = new String[k];//保存订餐人姓名；
        String[] dishMegs = new String[k];//保存所选信息（菜品名与份数；
        int[] times = new int[k];//保存送餐时间；
        String[] addresses = new String[k];//保存送餐地址；
        int[] states = new int[k];//保存订单状态；
        double[] sumPrices = new double[k];//保存订单的总金额；
        String[] CaiPin = {"红烧带鱼", "鱼香肉丝", "时令鲜蔬"};
        double[] prices = {38.0, 20.0, 10.0,};
        int[] DianZan = new int[3];
        System.out.println("欢迎使用：“吃货联盟订餐系统”");
        for (int z = 0; ; z++) {
            System.out.println("*******************************");
            System.out.println("1.我要订餐");
            System.out.println("2.查看餐袋");
            System.out.println("3.签收订单");
            System.out.println("4.删除订单");
            System.out.println("5.我要点赞");
            System.out.println("6.退出系统");
            System.out.println("*******************************");
            System.out.print("请选择：");
            int a = in.nextInt();
            switch (a) {
                case 1:
                    System.out.println("***我要订餐***");
                    for (int zz = 0; ; zz++) {
                        System.out.print("是/否下单？");
                        String b = in.next();
                        if (b.equals("是")) {
                            Boolean isAdd = false;
                            for (int i = 0; i < names.length; i++) {
                                if (names[i] == null) {
                                    isAdd = true;
                                    System.out.print("请输入姓名：");
                                    String b0 = in.next();
                                    System.out.println("序号" + "\t" + "菜名" + "\t" + "单价" + "\t" + "点赞数");
                                    for (int j = 0; j < CaiPin.length; j++) {
                                        String Prices = prices[j] + "元";
                                        String dianZan = (DianZan[j] > 0) ? DianZan[j] + "赞" : "0";
                                        System.out.println((j + 1) + "\t" + CaiPin[j] + "\t" + Prices + "\t" + dianZan);
                                    }
                                    System.out.print("请您选择要选的菜品编号：");
                                    int b1 = in.nextInt();
                                    while (b1 < 1 || b1 > 3) {
                                        System.out.print("输入错误，请重新输入。");
                                        b1 = in.nextInt();
                                    }
                                    System.out.print("请选择您需要的份数：");
                                    int b2 = in.nextInt();
                                    while (b2 <= 0) {
                                        System.out.print("输入错误，请重新输入。");
                                        b2 = in.nextInt();
                                    }
                                    System.out.print("请输入送餐时间（送餐时间是早上10点至晚上20点间整点配送)");
                                    int b3 = in.nextInt();
                                    while (b3 < 10 || b3 > 20) {
                                        System.out.println("输入错误，请输入10-20之间的整数！");
                                        b3 = in.nextInt();
                                    }
                                    System.out.print("请输入送餐地址：");
                                    String b4 = in.next();
                                    String CaiPins = CaiPin[b1 - 1] + " " + b2 + "份";
                                    double sumPrice = prices[b1 - 1] * b2;
                                    //是否有送餐费
                                    double SongCangFei = (sumPrice >= 50) ? 0 : 5;

                                    System.out.println("订餐成功！");
                                    System.out.println("您订的是：" + CaiPins);
                                    System.out.println("送餐时间：" + b3 + "点");
                                    System.out.println("餐费：" + sumPrice + "元。" + "送餐费：" + SongCangFei + "元。" + "总计：" + (sumPrice + SongCangFei) + "元。 ");
                                    names[i] = b0;
                                    dishMegs[i] = CaiPins;
                                    times[i] = b3;
                                    addresses[i] = b4;
                                    sumPrices[i] = sumPrice + SongCangFei;
                                    // System.out.println("输入0，返回。");
                                    break;
                                }
                            }
                            if (!isAdd) {
                                System.out.println("对不起；您的餐袋已满！");
                            }
                        } else {
                            System.out.println("返回上一菜单。");
                            break;
                        }
                    }
                    break;
                case 2:
                    System.out.println("***查看餐袋***");
                    for (int zz = 0; ; zz++) {
                        System.out.print("是/否查看订单？");
                        String b = in.next();
                        if (b.equals("是")) {
                            System.out.println("序号" + "\t\t" + "订餐人" + "\t\t" + "餐品信息" + "\t\t" + "送餐时间" + "\t " + "送餐地址" + "\t  " + "总金额" + "\t\t" + "订单状态");
                            for (int i = 0; i < names.length; i++) {
                                if (names[i] != null) {
                                    String state = (states[i] == 0) ? "已预订" : "已完成";
                                    String time = times[i] + "点";
                                    String sumPrice = sumPrices[i] + "元";
                                    System.out.println((i + 1) + "\t\t\t" + names[i] + "\t\t\t" + dishMegs[i] + "\t " + time + "\t\t" + addresses[i] + "\t\t" + sumPrice + "\t\t" + state);
                                }
                            }
                        } else {
                            System.out.println("返回上一菜单。");
                            break;
                        }
                    }
                    break;
                case 3:
                    for (int j = 0; j < names.length; j++) {
                        if (names[j] == null) {
                            System.out.println("您没有订单！");
                            break;
                        } else {
                            System.out.println("***签收订单***");
                            for (int zz = 0; ; zz++) {
                                System.out.print("是/否签收？");
                                String b = in.next();
                                if (b.equals("是")) {
                                    System.out.print("输入订单号：");
                                    int c = in.nextInt();
                                    for (int i = 0; i < names.length; i++) {
                                        if (names[i] != null && states[i] == 0 && c == i + 1) {
                                            states[i] = 1;
                                            System.out.print("订单签收成功！\n");
                                        } else if (names[i] != null && states[i] == 1 && c == i + 1) {
                                            System.out.print("该订单已签收过，无法再次签收！\n");
                                            break;
                                        }
                                    }
                                    if (c > names.length || c < 1) {
                                        System.out.print("您选择的订单不存在！");
                                    }
                                } else {
                                    System.out.println("返回上一菜单。");
                                    break;
                                }
                            }
                            break;
                        }
                    }
                    break;
                case 4:
                    for (int n = 0; n < names.length; n++) {
                        if (names[n] == null) {
                            System.out.println("您没有订单！");
                            break;
                        } else {
                            System.out.println("***删除订单***");
                            for (int zz = 0; ; zz++) {
                                System.out.print("是/否删除已完成的订单？");
                                String b = in.next();
                                if (b.equals("是")) {
                                    System.out.print("输入订单号：");
                                    int c = in.nextInt();
                                    int c1=0;
                                    for (int i = 0; i < names.length; i++) {
                                        if (names[i] != null && states[i] == 1 && c == i + 1) {
                                            for (int j = c - 1; j < names.length - 1; j++) {
                                                names[j] = names[j + 1];
                                                dishMegs[j] = dishMegs[j + 1];
                                                times[j] = times[j + 1];
                                                addresses[j] = addresses[j + 1];
                                                states[j] = states[j + 1];
                                                sumPrices[j] = sumPrices[j + 1];
                                            }
                                            int d = names.length - 1;
                                            names[d] = null;
                                            dishMegs[d] = null;
                                            times[d] = 0;
                                            addresses[d] = null;
                                            states[d] = 0;
                                            sumPrices[d] = 0;
                                            System.out.println("订单已删除！");
                                        } else if (names[i] != null && states[i] == 0 && c == i + 1) {
                                            System.out.println("该订单未签收，无法删除！");
                                            break;
                                        }
                                    }
                                    if (c>names.length||c<1||names[c-1]==null){
                                        System.out.print("您选择的订单不存在！\n");
                                    }
                                } else {
                                    System.out.println("返回上一菜单。");
                                    break;
                                }
                            }
                            break;
                        }
                    }
                    break;
                case 5:
                    System.out.println("***我要点赞***");
                    System.out.println("序号" + "\t" + "菜名" + "\t" + "单价" + "\t" + "点赞数");
                    for (int j = 0; j < CaiPin.length; j++) {
                        String Prices = prices[j] + "元";
                        String dianZan = (DianZan[j] > 0) ? DianZan[j] + "赞" : "0";
                        System.out.println((j + 1) + "\t" + CaiPin[j] + "\t" + Prices + "\t" + dianZan);
                    }
                    System.out.print("去选择您要点赞的菜品序号！");
                    int b=in.nextInt();
                    while (b>3||b<1){
                        System.out.print("输入错误，请重新输入。");
                        b=in.nextInt();
                    }
                    DianZan[b-1]=DianZan[b-1]+1;
                    System.out.println("点赞成功！");
                    break;
                    case 6:
                        System.out.println("***退出系统***");
                        System.out.println("欢迎使用，下次再见！");
                        return;
            }
            if (!(a >= 1 && a <= 6)) {
                System.out.println("输入错误，返回主菜单");
            }
            System.out.print("输入0返回");
            String x = in.next();
        }

    }
}

